import { useState } from "react";
const UserInfo = (props) => {
    const [userOld, setUserOld] = useState(props.old ?? '0');
    const handleCallback = (e) => {
         
        const newValue = e.target.value;
        setUserOld(newValue);
        //当前userOld不同才调用回调
        if (newValue && newValue !== userOld) {
            props.parentCallback(newValue);
        }
    }

    return (
        <div>
             
            <h2>{props.name}</h2>
            <input value={userOld} onChange={ handleCallback }/>
             
        </div>
    );
}
export default UserInfo;